<?php
defined ( '_FW_EXEC' ) or die ( 'Restricted access' );
RClassesImporter::cls("dbo.dtos.VideoDTO" );

class VideoModel {

	function delete($arrId) {
		$result = false;
		if (is_array($arrId)) {
			$arrId = implode(',', $arrId);
		}
		$sQuery		=	"DELETE FROM video WHERE video_id IN ({$arrId}) ";
		return SysDatabase::execute( $sQuery );
	}

	function getVideoDetails($id) {
		$my_Obj = new VideoDTO();
		$my_Obj->setKeyValue($id);
		SysDatabase::fillData($my_Obj);

		return $my_Obj;
	}


	function saveVideoDTO($dto){
		return SysDatabase::saveDTO($dto);
	}


	function getTranscationLog($id) {
		$finder = new TranscationFinder();
		$finder->member_id = $id;
		return SysDatabase::getSelectResult($finder->getSelectSQL());
	}

	/**
	 *
	 * Get video with paging
	 * @param $page
	 * @param $limit
	 * @return SelectResult
	 */
	function getVideoPaging($page, $limit = 6) {
		$sql = "SELECT * FROM video WHERE enabled = '1'";
		return SysDatabase::getSelectResult($sql, $limit, $page);
	}

	/**
	 * Toggle the value in fieldName corresponding to the id
	 *
	 * @param string $fiedName
	 * @param int $id
	 */
	function toggle($fiedName, $id) {
		if (!$id) {
			return false;
		}
		$sql = "UPDATE video SET {$fiedName} = NOT {$fiedName} WHERE video_id = '{$id}' ";
		return SysDatabase::execute($sql);
	}
}
?>